{extend name="mainadmin@layouts/base" /}
{block name="head" }
<link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.13.18/css/bootstrap-select.css" rel="stylesheet">
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.13.18/js/bootstrap-select.min.js"></script>
<style>
    .pop-area{line-height:1;margin-top:-10px;-webkit-user-select:none;width:830px}.
                                                                                  pop-area .check{margin-right:7px}
    .pop-area-row{border-bottom:1px solid #E8E8E8}
    .pop-area-provinces{margin:10px 0}
    .pop-area-provinces [disabled]{color:#aaa}
    .pop-area-region{position:relative;display:inline-block;width:98px}
    .pop-area-region .ys-hint3-content{left:-20px!important}
    .pop-area-region .ico-help-arrow{left:23px!important}
    .pop-area-region .ico-arrow-1{position:absolute;top:2px;right:15px}
    .pop-area-province{position:relative;display:inline-block;width:98px}
    .pop-area-province-arrow{cursor:pointer;display:inline-block;position:relative;padding:2px}
    .pop-area-province-arrow .ico{top:-2px}
    .pop-area-cities-count{font-size:12px;color:#49d}
    .check-inverse .pop-area-cities-count{color:#D55}
    .pop-area-cities{padding:15px 15px 0;border:1px solid #D8D8D8;border-radius:2px;background-color:#FCFCFC;position:relative;top:1px}
    .pop-area-cities [disabled]{color:#aaa}
    .pop-area-cities-arrow{position:absolute;top:-6px;left:0}
    .pop-area-city{position:relative;display:inline-block;margin:0 20px 10px 0}
    .pop-area-checkbox-warning{position:absolute;top:0;left:0;width:16px;height:16px;background:url(../img/ico.png) -340px -80px}
    .pop-area-checkbox-warning .ico-help{opacity:0}
    .pop-area-province .pop-area-checkbox-warning{top:2px}
    .caret-2 {
        border-top: none;
        border-bottom: 4px solid #000000;
    }

</style>

{/block}
{block name="main" }
<header class="header  b-b clearfix">
    <div class="page-breadcrumbs">
        <ul class="breadcrumb" >
            <li>
                <i class="fa fa-ellipsis-v"></i>
                <strong>新增会议</strong>
            </li>
        </ul>
        <a class="text-muted pull-right fr pointer m-t-md m-r" data-toggle="back" title="返回"><i class="fa fa-reply"></i></a>
    </div>
</header>

<form class="form-horizontal form-validate form_vbox" method="post" action="{:url('info')}">
    <section class="vbox">
        <section class="scrollable  wrapper w-f">

            <section class="panel panel-default">
                <div class="panel-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">会议名称：</label>
                        <div class="col-sm-3 must">
                            <input type="text" class="form-control" data-rule-required="true" name="meeting_name"
                                   value="{$row.meeting_name}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">绑定导师：</label>
                        <div class="col-sm-3 must">
                            <select name="user_id" style="width:100%;" data-toggle="select2" data-notsearch="true" data-placeholder="选择导师">
                                {foreach $userList as $item}
                                <option value="{$item.value}" <?php echo $row['user_id']==$item['value']?'selected':'';?> >{$item.label}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">开始时间：</label>
                        <div class="col-sm-3 must">
                            <input type="text" class="input-max" name="start_time" readonly="readonly" value="{$row.start_time|dateTpl='Y-m-d H:i',true}" data-before="#solddate"   data-toggle="datetimepicker" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">结束时间：</label>
                        <div class="col-sm-3 must">
                            <input type="text" class="input-max" name="end_time" readonly="readonly" value="{$row.end_time|dateTpl='Y-m-d H:i',true}" data-before="#solddate"   data-toggle="datetimepicker" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">商品佣金设置：</label>
                        <div class="col-sm-3 ">
                            <select id="goods" style="width:100%;" data-toggle="select2" data-notsearch="true" data-placeholder="选择导师">
                                {foreach $goodsList as $item}
                                <option value="{$item.goods_id}-{$item.goods_name}" data-name="{$item.goods_name}">{$item.goods_name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="col-sm-3 ">
                            <div class="input-group">
                            <input type="text" class="form-control"  name="commission"
                                  type="number"  value="{$row.commission}"/><span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <div class="btn-group" role="group" aria-label="...">
                            <button type="button" id="addGoods" class=" btn btn-default">添加</button>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">商品分佣信息</label>
                        <div id="info" class="col-sm-4">
                        </div>

                    </div>
                    <input type="hidden" value="" name="goods_ids" >
                    <input type="hidden" value="" name="info" >
                </div>
            </section>
        </section>

        <footer class="footer bg-white b-t p-t">
            <div class="form-group">
                <div class="col-sm-24 col-sm-offset-1">
                    <input name="id" type="hidden" value="{$row.id|intval}">
                    <button type="submit" class="btn btn-primary js_save_submit" data-loading-text="保存中...">保存
                    </button>
                    <button type="button" class="btn btn-default" data-toggle="back">取消</button>
                </div>
            </div>
        </footer>
    </section>
</form>


<script type="text/javascript">
    let info=[];
    let html =""
    let htmla =""
    let id =$('[name=id]').val();
    if(id!=0){
        info =JSON.parse('{$row.info|raw}')
        setHtml()
    }
    $("#addGoods").click(function (){
        let commission =$('[name=commission]').val()
        let str =$('#goods').val()
        if(commission ==="" || commission<=0){
            return layer.msg("佣金不能为空或者小于等于0")
        }
        let goods_id =str.split('-')[0]
        info.push({goods_id:goods_id,commission:commission,goods_name:str.split('-')[1]})

        setHtml()
    })
    function setHtml(){
        htmla =""
        let ids =[]
        info.map((v,i)=>{
            htmla+=
                "                            <div class='col-sm-10'><div class=\"input-group\">\n" +
                "                                <input type=\"text\" value='"+v.goods_name+"' class=\"form-control\" disabled>\n" +
                "                                <span class=\"input-group-addon\">分佣："+v.commission+"%</span></div></div><div class='col-sm-2'><button type=\"button\" onclick='delGoods("+i+")' class=\" btn btn-default\">删除</button></div>"
            ids.push(v.goods_id)
        })
        $("[name=goods_ids]").val(ids.join(','))
        $("[name=info]").val(JSON.stringify(info))
        html =htmla
        $("#info").html(html)
    }
    function delGoods(index){
        info.splice(index,1)
        setHtml()
    }
</script>


{/block}